<?php
/**
 * Created by PhpStorm.
 * User: venki
 * Date: 2023/11/18
 * Time: 15:55
 */

namespace app\behaviors;

use app\events\MessageEvent;
use app\Events\MyEvent;
use yii\base\Behavior;

class MessageBehavior extends Behavior
{
    const EVENT_MESSAGE = 'sendMessage';

    public function events()
    {
        return [
            MessageEvent::class => 'sendMessage',
        ];
    }

    public function sendMessage($message)
    {
        // 创建消息事件实例并触发事件
        $event = new MessageEvent($message);
        $this->owner->trigger(self::EVENT_MESSAGE, $event);
        echo 1222;
    }

    public function onSendMessage()
    {
        echo 3;
    }
}